<template>
  <div class="box-office" v-if="columnNum > 0">
    <header class="title">
      <span>票房</span>
      <span>票房详情 <van-icon name="arrow" /></span>
    </header>

    <van-grid :column-num="columnNum" direction="horizontal" v-if="columnNum > 0">

      <van-grid-item class="grid-item" v-if="lastDayRank > 0">
        <template #text>
          <div class="text">
            <div class="title">
              {{ lastDayRank }}
            </div>
            <div class="content">昨日排名</div>
          </div>
        </template>
      </van-grid-item>

      <van-grid-item class="grid-item" v-if="firstWeekBox > 0">
        <template #text>
          <div class="text">
            <div class="title">
              {{ formattedFirstWeekBox }}
            </div>
            <div class="content">首周票房(万)</div>
          </div>
        </template>
      </van-grid-item>

      <van-grid-item class="grid-item" v-if="sumBox > 0">
        <template #text>
          <div class="text">
            <div class="title">
              {{ formattedSumBox }}
            </div>
            <div class="content">累计票房(万)</div>
          </div>
        </template>
      </van-grid-item>
    </van-grid>
  </div>
</template>

<script setup>
import { computed } from 'vue'
const props = defineProps({
  movieBoxOffice: {
    type: Object,
  },
})

const lastDayRank = computed(() => {
  return props.movieBoxOffice.lastDayRank
})


const firstWeekBox = computed(() => {
  return props.movieBoxOffice.firstWeekBox
})

const sumBox = computed(() => {
  return props.movieBoxOffice.sumBox
})

// 格式化输出票房数据
const formattedFirstWeekBox = computed(() => {
  return props.movieBoxOffice.firstWeekBox.toLocaleString()
})

const formattedSumBox = computed(() => {
  return props.movieBoxOffice.sumBox.toLocaleString()
})

const columnNum = computed(() => {
  console.log('firstWeekBox', firstWeekBox.value);
  console.log('sumBox', sumBox.value);

  if (firstWeekBox.value > 0 && sumBox.value > 0 && lastDayRank.value > 0) {
    return 3
  } else if (
    (firstWeekBox.value > 0 && sumBox.value > 0 && lastDayRank.value === 0) ||
    (firstWeekBox.value > 0 && sumBox.value === 0 && lastDayRank.value > 0) ||
    (firstWeekBox.value === 0 && sumBox.value > 0 && lastDayRank.value > 0)
  ) {
    return 2
  } else if (
    (firstWeekBox.value > 0 && sumBox.value === 0 && lastDayRank.value === 0) ||
    (firstWeekBox.value === 0 && sumBox.value > 0 && lastDayRank.value === 0) ||
    (firstWeekBox.value === 0 && sumBox.value === 0 && lastDayRank.value > 0)
  ) {
    return 1
  }
  else {
    return 0
  }
});
</script>

<style scoped>
.box-office {
  margin-top: 10px;
  background-color: #fff;
  padding: 0 10px;
}

.box-office header.title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 15px;
  color: #333;
  padding: 10px 0;
}

.box-office header.title span:last-child {
  font-size: 12px;
  color: #999;
}

.grid-item {
  /* background-color: #f8f8f8; */
  padding-bottom: 10px;
}

.grid-item .title {
  font-size: 17px;
  color: #f03d37;
  text-align: center;
}

.grid-item .content {
  font-size: 12px;
  color: #666;
}

.van-grid {
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;

  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}

:deep(.van-grid-item.grid-item:first-child) {
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}

:deep(.van-grid-item__content:first-child) {
  border-top-left-radius: 10px;
  border-bottom-left-radius: 10px;
}

:deep(.van-grid-item.grid-item:last-child) {
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

:deep(.van-grid-item__content:last-child) {
  border-top-right-radius: 10px;
  border-bottom-right-radius: 10px;
}

:deep(.van-grid-item__content--center) {
  background-color: #f8f8f8;
  /* align-items: flex-start; */
  /* justify-content: flex-start; */
}

.box-office .content {
  background-color: #f8f8f8;
}
</style>
